package com.lianzhihui.romeex.utils.QrUtils;


/**
 * Description: 二维码相关工具类
 * Author: RAMON
 * CreateDate: 2020/9/24 2:32 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class QRUtils {

    public static final String QR_CODE_WALLET_RO_FLAG = "qrCodeRomeex/";  // 含有该字段表明是主网钱包的二维码
    public static final String QR_CODE_PRIVATE_KEY_FLAG = "privateKey=";  // 二维码私钥连接字段
    public static final String QR_CODE_ADDRESS_FLAG = "address=";  // 二维码地址连接字段
    public static final String QR_CODE_VALUE_FLAG = "value=";  // 二维码数目连接字段
    public static final String QR_INVITE = "invite=";  // 邀请码
    public static final String QR_CROSS = "cross=";  // 跨链
    public static final String QR_INTEGRAL = "integral=";  // 积分

    public final static String type1 = QR_CODE_WALLET_RO_FLAG + QR_CODE_VALUE_FLAG;
    public final static String type2 = QR_CODE_WALLET_RO_FLAG + QR_CODE_ADDRESS_FLAG;
    public final static String type3 = QR_CODE_WALLET_RO_FLAG + QR_CODE_PRIVATE_KEY_FLAG;
    public final static String type4 = QR_CODE_WALLET_RO_FLAG + QR_INVITE;
    public final static String type5 = QR_CODE_WALLET_RO_FLAG + QR_CROSS;
    public final static String type6 = QR_CODE_WALLET_RO_FLAG + QR_INTEGRAL;


    /**
     * 扫描结果
     *
     * @param content
     * @return 0 啥也不是，1 转账，2 地址，3 私钥, 4 邀请码, 5跨链
     */
    public static int scanType(String content) {

        if (content.startsWith(type1)) {
            return 1;
        }
        if (content.startsWith(type2)) {
            return 2;
        }
        if (content.startsWith(type3)) {
            return 3;
        }
        if (content.startsWith(type4)) {
            return 4;
        }
        if (content.startsWith(type5)) {
            return 5;
        }
        if (content.startsWith(type6)) {
            return 6;
        }
        return 0;
    }

    /**
     * 获取 该应用生成 二维码 的内容
     *
     * @param content
     * @param type
     * @return
     */
    public static String getContentString(String content, int type) {
        String str = "";
        switch (type) {
            case 1:
                str = type1;
                break;
            case 2:
                str = type2;
                break;
            case 3:
                str = type3;
                break;
            case 4:
                str = type4;
                break;
            case 5:
                str = type5;
                break;
            case 6:
                str = type6;
                break;
            default:
                str = "";
                break;
        }
        return content.replace(str, "");
    }

    /**
     * 自动判断类型，并返回内容
     *
     * @param content
     * @return
     */
    public static String getContentAuto(String content) {
        int type = scanType(content);
        return getContentString(content, type);
    }
}
